#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        if(stones.size()==1){
            return stones[0];
        }
        priority_queue<int> Q;
        for(int a:stones){
            Q.push(a);
        }
        while(Q.size()>1){
            int a = Q.top();
            Q.pop();
            int b = Q.top();
            Q.pop();
            if(a!=b){
                Q.push(abs(a-b));
            }
        }
        if(Q.size()==1){
        return Q.top();}
        else{
            return 0;
        }
    }
};

int main(){
    Solution S;
    vector<int> stones = {2,2};
    cout<<S.lastStoneWeight(stones)<<endl;
}